﻿using Engine;
using Engine.Graphics;
using Game;

namespace Mekiasm.Buff
{
    public class BuffView : CanvasWidget
    {
        public StackPanelWidget verLine = new StackPanelWidget() { Direction = LayoutDirection.Vertical, HorizontalAlignment = WidgetAlignment.Center, VerticalAlignment = WidgetAlignment.Center };
        public CircleImageWidget circleImageWidget = new CircleImageWidget();
        public CanvasWidget canvasWidget = new CanvasWidget() { Size = new Vector2(120, 40) };
        public LabelWidget msg = new LabelWidget() { FontScale = 0.5f };
        public BevelledRectangleWidget bevelled = new BevelledRectangleWidget() { BevelColor = Color.White, CenterColor = Color.Black, BevelSize = 2f };
        public Buff Buff;
        public BuffView(Buff buff)
        {
            Size = new Vector2(48, 48);
            Children.Add(verLine);
            canvasWidget.Children.Add(bevelled);
            msg.Size = canvasWidget.Size;
            canvasWidget.Children.Add(msg);
            verLine.Children.Add(circleImageWidget);
            Children.Add(canvasWidget);
            SetWidgetPosition(canvasWidget, new Vector2(36, 30));
            Buff = buff;
            circleImageWidget.isFlip = true;
            circleImageWidget.Texture = buff.Icon;
        }
        public override void Update()
        {
            if (Buff != null)
            {
                circleImageWidget.Progess = Buff.Progress;
                msg.UpdateLines(120f, 40f);
            }
            if (Input.Press.HasValue)
            {
                if (HitTest(Input.Press.Value))
                {
                    canvasWidget.IsVisible = true;
                    msg.Text = Buff.desc + "\n" + Buff.RemainTime + "s";
                }
            }
            else
            {
                canvasWidget.IsVisible = false;
            }
        }
    }
}
